# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')

class JT_9101:
	result=[]
	analysisDescription =['服务器IP地址长度：','服务器IP地址：','服务器视频通道监听端口号(TCP)：',
					'服务器视频通道监听端口号（UDP）：','逻辑通道号：','数据类型：','码流类型：']

	def LogicAisle(self, protocolStr, header):
		count=0
		s=""
		s="0x"+protocolStr[:2]
		n=int(s,16)
		analysis9101Length=[1,n,2,2,1,1,1]
		for i in range(len(self.analysisDescription)):
			#数据类型
			if i==5:
				s=protocolStr[count:count + (analysis9101Length[i] * 2)]
				if s=="00":
					header.append(self.analysisDescription[i]+s+" 音视频"+"\n")
				elif s=="01":
					header.append(self.analysisDescription[i] + s + " 视频" + "\n")
				elif s=="02":
					header.append(self.analysisDescription[i] + s + " 双向对讲" + "\n")
				elif s=="03":
					header.append(self.analysisDescription[i] + s +" 监听" + "\n")
				elif s=="04":
					header.append(self.analysisDescription[i] + s + " 中心广播" + "\n")
				elif s=="05":
					header.append(self.analysisDescription[i] + s + " 透传" + "\n")
				count = count + analysis9101Length[i] * 2
			#码流类型
			elif i==6:
				s = protocolStr[count:count + (analysis9101Length[i] * 2)]
				if s == "00":
					header.append(self.analysisDescription[i] + s + " 主码流" + "\n")
				elif s=="01":
					header.append(self.analysisDescription[i] + s + " 子码流" + "\n")
					count = count + analysis9101Length[i] * 2
			#服务器IP地址
			elif i==1:
				s = protocolStr[count:count+(analysis9101Length[i] * 2)].decode("hex").decode('gb2312')
				header.append(self.analysisDescription[i] + s + "\n")
				count = count + analysis9101Length[i] * 2
			#TCP端口号
			elif i==2:
				s="0x"+protocolStr[count:count+(analysis9101Length[i] * 2)]
				n=int(s,16)
				header.append(self.analysisDescription[i] +str(n) + "\n")
				count = count + analysis9101Length[i] * 2
			#UDP端口号
			elif i==3:
				s="0x"+protocolStr[count:count+(analysis9101Length[i] * 2)]
				n=int(s,16)
				header.append(self.analysisDescription[i] + str(n) + "\n")
				count = count + analysis9101Length[i] * 2
			else:
				header.append(self.analysisDescription[i] + protocolStr[count:count + (analysis9101Length[i] * 2)] + "\n")
				count = count + analysis9101Length[i] * 2

		self.result = header
